import win32gui
import win32con
import win32clipboard as w
import time
import random

msg = "聊天的内容"

name = "聊天对象昵称"
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_UNICODETEXT, msg)
w.CloseClipboard()

hand = win32gui.FindWindow(None, name)
n = 0
while n < 4:
    win32gui.SendMessage(hand, 770, 0, 0)
    win32gui.SendMessage(hand, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
    n += 1
